{extend name='base' /}
{block name='content'}
<body>
<div class="x-body">
    <form class="layui-form" id="AddData">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>文章标题
            </label>
            <div class="layui-input-inline">
                <input type="text" name="title" required="" lay-verify="required" autocomplete="off" value=""
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>每个文章类型中的唯一标识
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>所属分类
            </label>
            <div class="layui-input-inline">
                <select name="cate_id" lay-verify="required">
                    <option value="">请选择分类</option>
                    {volist name='CateData' id='vo'}
                    <option value="{$vo.cate_id}">{$vo.cate_name}</option>
                    {/volist}
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>文章类型标识
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否显示</label>
            <div class="layui-input-block">
                <input type="checkbox" name="status" lay-skin="switch" checked>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="x-red">*</span>文章描述</label>
            <div class="layui-input-block">
                <textarea name="describe" placeholder="请输入描述内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>文章内容</label>
            <div class="layui-input-block">
                <textarea name="content" id="content" style="height: 300px"></textarea>
            </div>
        </div>
        <input type="hidden" name="draft" value="1" id="draft">
        <div class="layui-form-item">
            <label  class="layui-form-label">
            </label>
            <a class="layui-btn" href="javascript:Add();">
                增加
            </a>
            <a class="layui-btn layui-btn-primary" href="javascript:Draft();">
                保存草稿
            </a>
        </div>
    </form>
</div>
<script>
    var ue = UE.getEditor('content', {
        zIndex: 1,
    });
    function Draft() {
        $('#draft').val('0');
        foo();
    }
    function Add() {
        $('#draft').val('1');
        foo()
    }

    function foo() {
        $.ajax({
            url: "{:url('article/add')}",
            type: 'post',
            dataType: 'json',
            data: $('#AddData').serialize(),
            success: function (res) {
                if (res.code == 1) {
                    layer.msg(res.message, {icon: 6});
                    setTimeout(function () {
                        x_admin_close();
                        window.parent.location.reload();
                    }, 1000)
                } else {
                    layer.msg(res.message, {icon: 2, time: 1000})
                }
            },
            error: function () {
                layer.msg('出错了，请稍后再试！', {icon: 5, time: 1000})
            }
        })
    }
</script>
</body>
{/block}